package com.chouxiaozi.dynamicproxy.cxzproxy;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class CxzMeipo implements CxzInvocationHandler {

    private Object target;

    public Object getInstance(Object target){
        this.target = target;
        Class<?> clazz = target.getClass();
        return CxzProxy.newProxyInstance(new CxzClassLoader(), clazz.getInterfaces(), this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object object = method.invoke(this.target, args);
        after();
        return object;
    }

    private void before(){
        System.out.println("我是媒婆，我准备开始给你找对象");
    }
    private void after(){
        System.out.println("牵线成功，在一起吧");
    }
}
